<style type="text/css">
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110">
        <Form-item label="快递公司名称" prop="expresscompany">
            <i-select v-model="formValidate.expresscompany" placeholder="请选择快递公司名称">
                <template v-for="(item,index) in expressArr">
                    <i-option :value="item.Value">{{item.Value}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="快递单号" prop="expresscode">
            <i-input v-model="formValidate.expresscode" placeholder="请输入快递单号"></i-input>
        </Form-item>
        <selectSearch :selectBaseInfo="selectBaseInfo" @post-data="getCompentensData"></selectSearch>
        <Form-item label="收件人联系电话" prop="peoplecontact">
            <i-input v-model="formValidate.peoplecontact" placeholder="请输入收件人联系电话"></i-input>
        </Form-item>
        <Form-item label="收件人地址" prop="peopleaddress">
            <i-input v-model="formValidate.peopleaddress" placeholder="请输入收件人收件人地址"></i-input>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost"  @click="jumpPage('','ExpressInfoList')" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';
    import selectSearch from '../../components/selectSearch';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    expresscode: '',
                    expresscompany: '',
                    peoplecontact: '',
                    peopleaddress: '',
                    expresstype: '收件',
                },
                ruleValidate: {
                },
                //快递公司列表
                expressArr:[],
                //选择人员
                selectBaseInfo: {
                    "title": '选择人员',
                    "placeholder": '请输入姓名',
                    "postUrl": apiUtil.urls.userList,
                    'postType': 'user',
                },
                reqpeopleDept: '',
            }
        },
        mounted: function () {
           this.getExpressData();
        },
        components: {
            selectSearch
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            addData: function (model) {
                let that = this;

                model.peopleid = this.reqpeopleDept.resultId;
                model.peoplename = this.reqpeopleDept.resultName;
                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.AddExpressInfo, params, function (res) {
                    that.$Loading.finish();
                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {},
                        onCancel: () => {
                            baseUtil.pageJump(that,'','ExpressInfoList')
                        }
                    });
                });
            },
            //获取选择搜索组件传来结果数据
            getCompentensData: function (value) {
                this.reqpeopleDept = value;
            },

            //获取快递公司列表
            getExpressData: function (model) {
                let that = this;

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.get(that,apiUtil.urls.ExpressList, params, function (res) {
                    that.$Loading.finish();

                    that.expressArr = res.Msg;
                });
            },

        }
    }
</script>
